<?php
/**
 * admin service file Created by PhpStorm.
 * User: yang
 * Date: 2020/04/30
 */

namespace App\Http\Service\Web;

use Common\Repository\ForumCommentRepository;
use Common\Repository\ForumRepository;
use Illuminate\Support\Facades\Redis;

class IndexService
{
    /**
     * @return array
     */
    public function index()
    {
        try {
            $user = web_user_info();
            $top = ForumRepository::extendGetTop();

            $arr_option['limit'] = 15;
            $arr_option['with'] = ['get_user', 'get_type'];
            $arr_option['where'] = ['status' => 0, 'is_top' => 0];
            $arr_option['withCount'] = ['get_comment'];
            if ($user) {
                $arr_option['orWhere']['user_id'] = $user['id'];
                $arr_option['orWhere']['is_top'] = 0;
            }
            $list = ForumRepository::getList($arr_option);

            $type = \App\Http\Service\Admin\ForumTypeService::getAll();

            $host = ForumService::hostList();//最近热议

            $reply = ForumCommentRepository::extendReplyList();//回复榜

            $result = [
                'type' => $type,
                'top' => $top,
                'list' => $list['data'],
                'user' => $user,
                'path' => '/forumList/0',
                'host' => $host,
                'reply'=> $reply
            ];

            return $result;
        } catch (\Exception $exception) {
            return hello_error('失败！', $exception->getMessage());
        }
    }



}